package org.rsbot.script.methods;

import java.util.ArrayList;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSItem;

public class Combat extends MethodProvider
{
  public Combat(MethodContext paramMethodContext)
  {
    super(paramMethodContext);
  }

  public boolean Eat(int paramInt, int[] paramArrayOfInt)
  {
    int i = getHealth();
    for (int m : paramArrayOfInt) {
      if (!this.methods.inventory.contains(m)) {
        continue;
      }
      if (this.methods.inventory.getItem(new int[] { m }).doAction("Eat")) {
        for (int n = 0; n < 100; n++) {
          sleep(random(100, 300));
          if (i < paramInt) {
            break;
          }
        }
      }
      if (getHealth() >= paramInt) {
        return true;
      }
    }
    return false;
  }

  public void setAutoRetaliate(boolean paramBoolean)
  {
    RSComponent localRSComponent = this.methods.interfaces.getComponent(884, 15);
    if (isAutoRetaliateEnabled() != paramBoolean) {
      if (this.methods.game.getCurrentTab() != 0) {
        this.methods.game.openTab(0);
      }
      if ((this.methods.game.getCurrentTab() == 0) && (localRSComponent != null))
      {
        localRSComponent.doClick();
      }
    }
  }

  public boolean isAutoRetaliateEnabled()
  {
    return this.methods.settings.getSetting(172) == 0;
  }

  public int getFightMode()
  {
    return this.methods.settings.getSetting(43);
  }

  public boolean setFightMode(int paramInt)
  {
    if (paramInt != getFightMode()) {
      this.methods.game.openTab(0);
      if (paramInt == 0)
        return this.methods.interfaces.getComponent(884, 11).doClick();
      if (paramInt == 1)
        return this.methods.interfaces.getComponent(884, 12).doClick();
      if ((paramInt == 2) || ((paramInt == 3) && (this.methods.interfaces.getComponent(884, 14).getActions() == null)))
      {
        return this.methods.interfaces.getComponent(884, 13).doClick();
      }if (paramInt == 3) {
        return this.methods.interfaces.getComponent(884, 14).doClick();
      }
    }
    return false;
  }

  public int getWildernessLevel()
  {
    return this.methods.interfaces.get(381).getComponent(1).isValid() ? Integer.parseInt(this.methods.interfaces.get(381).getComponent(1).getText().replace("Level: ", "").trim()) : 0;
  }

  public int getLifePoints()
  {
    try
    {
      return Integer.parseInt(this.methods.interfaces.get(748).getComponent(8).getText());
    } catch (NumberFormatException localNumberFormatException) {
    }
    return 0;
  }

  public boolean isPrayerOn(Prayer paramPrayer)
  {
    RSComponent[] arrayOfRSComponent1 = this.methods.interfaces.getComponent(271, 7).getComponents();

    for (RSComponent localRSComponent : arrayOfRSComponent1)
      if ((localRSComponent.getComponentIndex() == paramPrayer.getIndex()) && (localRSComponent.getBackgroundColor() != -1))
      {
        return true;
      }
    return false;
  }

  public boolean isQuickPrayerOn()
  {
    return this.methods.interfaces.getComponent(749, 2).getBackgroundColor() == 782;
  }

  public boolean setPrayer(Prayer paramPrayer, boolean paramBoolean)
  {
    this.methods.game.openTab(6);
    if (this.methods.interfaces.getComponent(271, 7).getComponents()[paramPrayer.getIndex()].getBackgroundColor() == -1);
    return this.methods.interfaces.getComponent(271, 7).getComponents()[paramPrayer.getIndex()].doAction(paramBoolean ? "Activate" : "Deactivate");
  }

  public RSComponent[] getSelectedPrayers()
  {
    ArrayList localArrayList = new ArrayList();
    RSComponent[] arrayOfRSComponent1 = this.methods.interfaces.getComponent(271, 7).getComponents();

    for (RSComponent localRSComponent : arrayOfRSComponent1) {
      if (localRSComponent.getBackgroundColor() != -1) {
        localArrayList.add(localRSComponent);
      }
    }
    return (RSComponent[])localArrayList.toArray(new RSComponent[localArrayList.size()]);
  }

  public boolean isPoisoned()
  {
    return (this.methods.settings.getSetting(102) > 0) || (this.methods.interfaces.getComponent(748, 4).getBackgroundColor() == 1801);
  }

  public boolean isSpecialEnabled()
  {
    return this.methods.settings.getSetting(301) == 1;
  }

  public int getSpecialBarEnergy()
  {
    return this.methods.settings.getSetting(300);
  }

  public int getPrayerPoints()
  {
    try
    {
      return Integer.parseInt(this.methods.interfaces.get(749).getComponent(4).getText().trim());
    }
    catch (NumberFormatException localNumberFormatException) {
    }
    return 0;
  }

  public int getHealth()
  {
    return getLifePoints() * 10 / this.methods.skills.getRealLevel(3);
  }

  public static enum Prayer
  {
    THICK_SKIN(0, 1), BURST_OF_STRENGTH(1, 4), CLARITY_OF_THOUGHT(2, 7), SHARP_EYE(3, 8), 
    MYSTIC_WILL(4, 9), ROCK_SKIN(5, 10), SUPERHUMAN_STRENGTH(6, 13), 
    IMPROVED_REFLEXES(7, 16), RAPID_RESTORE(8, 19), RAPID_HEAL(9, 22), 
    PROTECT_ITEM(10, 25), HAWK_EYE(11, 26), MYSTIC_LORE(12, 27), 
    STEEL_SKIN(13, 28), ULTIMATE_STRENGTH(14, 31), INCREDIBLE_REFLEXES(15, 34), 
    PROTECT_FROM_SUMMONING(16, 35), PROTECT_FROM_MAGIC(17, 37), 
    PROTECT_FROM_MISSILES(18, 40), PROTECT_FROM_MELEE(19, 43), EAGLE_EYE(20, 44), 
    MYSTIC_MIGHT(21, 45), RETRIBUTION(22, 46), REDEMPTION(23, 49), 
    SMITE(24, 52), CHIVALRY(25, 60), RAPID_RENEWAL(26, 65), PIETY(27, 70), 
    RIGOUR(28, 74), AUGURY(29, 77), 

    PROTECT_ITEM2(0, 50), SAP_WARRIOR(1, 50), SAP_RANGER(2, 52), SAP_MAGE(3, 54), 
    SAP_SPIRIT(4, 56), BERSERKER(5, 59), DEFLECT_SUMMONING(6, 62), 
    DEFLECT_MAGIC(7, 65), DEFLECT_MISSLE(8, 68), DEFLECT_MELEE(9, 71), 
    LEECH_ATTACK(10, 74), LEECH_RANGE(11, 76), LEECH_MAGIC(12, 78), 
    LEECH_DEFENCE(13, 80), LEECH_STRENGTH(14, 82), LEECH_ENERGY(15, 84), 
    LEECH_SPECIAL_ATTACK(16, 86), WRATH(17, 89), SOUL_SPLIT(18, 92), 
    TURMOIL(19, 95);

    private int index;
    private int level;

    private Prayer(int paramInt1, int paramInt2) { this.index = paramInt1;
      this.level = paramInt2; }

    public int getIndex()
    {
      return this.index;
    }

    public int getRequiredLevel() {
      return this.level;
    }
  }
}